package com.hxkj.cst.chengshuitong.ui.fragment

import android.content.res.TypedArray
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.SparseArray
import android.view.View
import com.hxkj.cst.chengshuitong.R
import com.hxkj.cst.chengshuitong.RatePaymentEnum
import com.hxkj.cst.chengshuitong.base.RatePaymentFragment
import com.hxkj.cst.chengshuitong.ui.adapter.RatePaymentTableAdapter
import kotlinx.android.synthetic.main.fragment_third_payment.view.*

/**
 * 作者：LuoYang
 * 时间：2017/5/31:15:41
 * 邮箱：18981443691@163.com
 * 说明：
 */
class RatePaymentThirdFragment : RatePaymentFragment() {
    var mRvContain: RecyclerView? = null
    override fun provideContentView(): Int = R.layout.fragment_third_payment

    override fun initLayout(view: View) {
        mRvContain = view.fthird_rv_contain
        setUpRecyclerView()

        view.fthird_btn_sure.setOnClickListener {
            notifyObserver(RatePaymentEnum.FOURTH_RATE_PAYMENT)
        }
    }

    fun setUpRecyclerView(): Unit {
        val layoutManager = LinearLayoutManager(activity)
        layoutManager.orientation = LinearLayoutManager.VERTICAL
        mRvContain?.layoutManager = layoutManager

        val typeArrays: TypedArray = activity.resources
                .obtainTypedArray(R.array.RatePayment_Third_Describe)
        val sparseArray = SparseArray<String>()
        for (index in 0..typeArrays.length() - 1) {
            sparseArray.put(index, "测试数据${typeArrays.getString(index)}")
        }
        typeArrays.recycle()

        val adapter = RatePaymentTableAdapter(activity,
                sparseArray,
                R.array.RatePayment_Third_Describe)

        adapter.setBackgroundColor(R.color.material_white)

        mRvContain?.adapter = adapter
    }
}